#!/bin/bash
# 作用：分发文件到所有节点
if [ $# -eq 0 ]
then
	echo "请输入要分发的文件/目录！" && exit
fi

for file in $@
do
	if [ -e $file ]
	then
		for host in hadoop102 hadoop103 hadoop104
		do
			echo "========== $host =========="
			dir_name=$(cd -P $(dirname $file);pwd)
			file_name=$(basename $file)
			ssh $host "mkdir -p $dir_name"
			rsync -av $dir_name/$file_name $host:$dir_name/
		done
	else
		echo "文件/目录不存在，请输入正确的文件/目录！" && exit
	fi
done